package com.singzi.leetcode.N100;

public class T0038 {
    public static void main(String[] args) {
        Solution0038 solution0038 = new Solution0038();
        System.out.println(solution0038.countAndSay(8));

    }
}
class Solution0038 {

    public String countAndSay(int n) {
        if(n == 1) return "1";
        String s1 = "1";
        n = n-1;
        while(n>0){
            s1 = andSay(s1);
            n--;
        }
        return s1;
    }
    public String andSay(String str){
        int count;

        int m = str.length();
        String str1 = "";
        for(int i = 0;i < m;i++){
            count = 1;
            for(int j = i+1;j<m;j++){
                if(str.charAt(i) == str.charAt(j)){
                    i++;
                    count = count+1;
                }
                else break;

            }
            str1 = str1+count+str.charAt(i);
        }
        return str1;

    }
}